package com.smasher.component.activity

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.smasher.component.R
import com.smasher.component.adapter.DecorationAdapter
import com.smasher.decoration.GroupDecoration
import com.smasher.decoration.group.GroupSwordDecoration

class DecorationActivity : AppCompatActivity() {

    private lateinit var mRecyclerView: RecyclerView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_decoration)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        mRecyclerView = findViewById(R.id.recycler_view)
        mRecyclerView.layoutManager = LinearLayoutManager(this)
        mRecyclerView.adapter = DecorationAdapter().apply {
            setData(
                listOf(
                    "item1",
                    "item2",
                    "item3",
                    "item4",
                    "item5",
                    "item6",
                    "item7",
                    "item8",
                    "item9",
                    "item10",
                    "item11",
                    "item12",
                    "item13",
                    "item14",
                    "item15",
                    "item16",
                    "item17",
                    "item18",
                    "item19",
                    "item20",
                    "item21",
                    "item22",
                    "item23",
                    "item24",
                    "item25",
                    "item26",
                    "item27",
                    "item28",
                    "item29",
                    "item30",
                    "item31",
                    "item32",
                    "item33",
                    "item34",
                    "item35"
                )
            )
        }
        val type1 = false
        if (type1) {
            mRecyclerView.addItemDecoration(GroupDecoration(this).apply {
                setCategoryList(
                    listOf(
                        "分组1",
                        "分组1",
                        "分组1",
                        "分组1",
                        "分组1",
                        "分组1",
                        "分组1",
                        "分组1",
                        "分组1",
                        "分组2",
                        "分组2",
                        "分组2",
                        "分组2",
                        "分组2",
                        "分组2",
                        "分组2",
                        "分组2",
                        "分组2",
                        "分组2",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3",
                        "分组3"
                    )
                )

            })
        } else {
            mRecyclerView.addItemDecoration(GroupSwordDecoration(this))
        }

    }
}